$(function () {
    function getgsshop() {

        $.ajax({
            type: 'get',
            url: 'http://localhost:3000/api/getgsshop',
            dataType: 'json', //text,json,xml,jsonp
            success(res) {
                console.log(res)
                $('#shop ul').html(template('getgsshopTpl', res))
            }
        })
    }

    $('#shop ul').on('click', 'li', function () {
        let id = $(this).data('id');
        console.log(id);
        if ($('#shop li').length > 3) {
            render(areaid = id);
            areaid = id;
        } else {
            render(shopid = id);
            shopid = id;
        }
        $('#shop').hide();
        render(shopid, areaid);
    })

    $('.list .filter').on('click', 'li', function () {
        let id = $(this).data("id");
        console.log('1234', id);
        // data() 获取id 要加引号
        $('#shop').show();
        if (id == 'getgsshop') {
            getgsshop()
        } else {
            getgsshoparea()
        }
    })

    function getgsshoparea() {

        $.ajax({
            type: 'get',
            url: 'http://localhost:3000/api/getgsshoparea',
            dataType: 'json', //text,json,xml,jsonp
            success(res) {
                console.log(res)
                $('#shop ul').html(template('getgsshopareaTpl', res))
            }
        })
    }

    function render(shopid = 0, areaid = 0) {
        $.ajax({
            type: 'get',
            url: 'http://localhost:3000/api/getgsproduct',
            data: {
                shopid,
                areaid
            },
            dataType: 'json', //text,json,xml,jsonp
            success(res) {
                console.log(res)
                $('#container').html(template('getgsproductTpl', res))
            }
        })
    }
    render();
})